package com.example.myapplication.kotlin

fun main() {
    val age1 = ifDemo(20)
    println(age1)
    val foods = whenDemo("苹果")
    println(foods)
    println(getGrade(80))
}

// if语句
fun ifDemo(age: Int): String {
    if (age >= 18) {
        return "已成年"
    } else if (age >= 6) {
        return "青少年"
    } else {
        return "未成年"
    }
}

// when语句
fun whenDemo(food: String): Number {
    val price = when (food) {
        "苹果" -> 1
        "香蕉" -> 2
        "橘子" -> 3
        else -> -1
    }
    return price
}

// 根据分数 返回评级，用when实现
fun getGrade(score: Int): String {
    return when (score) {
        in 0..59 -> "不及格"
        in 60..69 -> "及格"
        in 70..79 -> "良好"
        in 80 until 90 -> "优秀"
        in 90..100 -> "优秀"
        else -> "输入的分数有误"
    }
}